//
//  ClassModelView.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/16.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "ClassModelView.h"
#import "ClassModel.h"

@implementation ClassModelView

- (instancetype)init{
    
    if (self = [super init]) {
        
        _sourceArr = [NSMutableArray array];
    }
    
    return self;
}

- (void)getClassData{

    NSDictionary *dic = @{@"oauth_token":@"815bffb68e2ea44e38cf16a98a5a29a4",@"oauth_token_secret":@"8e84bc64f03d73b5c75406ef1d7349f7"};
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    SCHttpRequest *request = [[SCHttpRequest alloc]initWithApi:API_AllCourse params:params];
    
    [self doPOSTConnect:request start:^(SCHttpRequest * _Nonnull req) {
        
    } success:^(SCHttpRequest * _Nonnull req, SCHttpResponse * _Nonnull resp) {
        
        NSLog(@"originalDictionary == %@", resp.originalDictionary[@"data"]);
        
        NSArray *zhangArr = [NSArray arrayWithArray:resp.originalDictionary[@"data"]];
        
        NSMutableArray *subArray = [NSMutableArray array];
        
        NSMutableArray *allArr = [NSMutableArray array];
        
        if (zhangArr.count > 0) {
            
            for (int i = 0; i < zhangArr.count; i++) {
                
                ClassModel *zhangModel = [ClassModel modelWithDic:zhangArr[i]];
                
                [allArr addObject:zhangModel];
                
                NSArray *subArr = zhangArr[i][@"sub"];
                
                if (subArr.count > 0) {
                    
                    for (int j = 0; j < subArr.count; j++) {
                        
                        ClassModel *jieModel = [ClassModel modelWithDic:subArr[j]];
                        
                        [subArray addObject:jieModel];
                    }
                }
                
                NSArray *dataArr = [NSArray arrayWithArray:subArray];
                
                [_sourceArr addObject:dataArr];
                
                [subArray removeAllObjects];
                
            }
                    
            NSLog(@"sourceArr == %@", zhangArr);
        
        _succeedBlock(allArr, _sourceArr);
        
        }
        
    } failure:^(SCHttpRequest * _Nonnull req, NSError * _Nonnull error) {
        
        _faileBlock(error);
        
    } finish:^(SCHttpRequest * _Nonnull req, BOOL success) {
        
    }];
}

@end
